package com.springboot.controller;

import com.springboot.mapper.UserMapper;
import com.springboot.pojo.User;
import com.springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    // 代理对象可直接在ioc容器中拿到了
    @Autowired
    private UserMapper userMapper;

    @Autowired
    private UserService userService;

    @GetMapping("/qa")
    public List<User> queryAll() {
        return userMapper.queryAll();
    }

    @GetMapping("/do")
    // 有jdbc启动器，springboot会自动配置一个DataSourceTransactionManager，不需要我们写事务管理器了，只需要写注解就生效
    @Transactional
    public void deleteOne() {
        userService.deleteByPrimaryKey(1);
    }



}
